package com.song.shop.ioc;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;

/**
 * @author Song Yinghui
 * @date 2018/11/1
 * @Version 1.0
 *
 * spring ioc
 */
public class IocTest {


    public static void main(String[] args) throws Exception {

        Class<?> clazz = Class.forName("com.song.shop.ioc.IocTest1");
        System.out.println("simplename="+clazz.getSimpleName());
        System.out.println("---"+clazz.getName());
        Class<?>[] interfaces = clazz.getInterfaces();
        for (Class<?> i : interfaces){
            System.out.println(i.getName());
            System.out.println(i.getSimpleName());
        }
        System.out.println("--------------fields-----------");

        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field d : declaredFields){
            if (!d.isAnnotationPresent(GPAutowired.class)){
                d.setAccessible(true);
                if ("str".equals(d.getName())){
                    d.set(clazz, "songyinghui");
                }else {
                    continue;
                }
            }
            System.out.println(d.getType().getName());
            System.out.println(d.getType().getSimpleName());
        }


        System.out.println("----------classpath-----");
        URL resource = IocTest.class.getResource("/"+"com.song.shop");
        System.out.println(IocTest.class.getResource("/redis.properties"));
//        System.out.println(IocTest.class.getResource());
        System.out.println(IocTest.class.getClassLoader().getResource("redis.properties"));
//        System.out.println(IocTest.class.getClassLoader().getResource());

        System.out.println("----------method-----");

        Method[] methods = clazz.getMethods();
        for (Method m : methods){
            if ("test2".equals(m.getName()) ){
                m.invoke(clazz.newInstance(), "songyinghui");
            }
        }

    }
}
